// by Xeno
#define THIS_FILE "x_intro.sqf"
#include "x_setup.sqf"
private ["_s","_str"];
if (!X_Client) exitWith {};

enableRadio false;

disableSerialization;

waitUntil {sleep 0.112;!isNil QGVAR(preloaddone)};
sleep 0.01;
1 fadeSound 1;

GVAR(still_in_intro) = true;

showCinemaBorder true;

createDialog "X_RscAnimatedLetters";
setMousePosition [1, 1];
_line = 0;
GVAR(animL_i) = 0;
titleText ["", "BLACK IN",0];
88 cutrsc ["RscStatic","PLAIN"];

//Sign_Arrow_Location_F
_arrow_over_head = "Sign_Arrow_Large_F" createVehicleLocal [getPosASL player select 0, getPosASL player select 1, 2.2];
_arrow_over_head setPos [getPosASL player select 0, getPosASL player select 1, 2.2];
_arrow_over_head spawn {
	private ["_dir", "_arr"];
	_dir = 0;
	_arr = _this;
	while {!isNull _arr} do {
		_arr setDir _dir;
		__INC(_dir);
		if (_dir == 360) then {_dir = 0};
		sleep 0.005;
	};
};

"dynamicBlur" ppEffectEnable true;
"dynamicBlur" ppEffectAdjust [6];
"dynamicBlur" ppEffectCommit 0;
"dynamicBlur" ppEffectAdjust [0.0];
"dynamicBlur" ppEffectCommit 15;

playMusic "DomIntro";

if (sunOrMoon == 0) then {camUseNVG true};

#ifndef __TT__
GVAR(intro_color) = switch (GVAR(own_side)) do {case "BLUFOR": {[0.85,0.88,1,1]};case "OPFOR": {[1,0.36,0.34,1]};case "INDEPENDENT": {[1,1,0,1]};};
_camstart = markerPos QGVAR(camstart);
deleteMarkerLocal QGVAR(camstart);
#endif
#ifdef __TT__
GVAR(intro_color) = if (playerSide == blufor) then {[0.85,0.88,1,1]} else {[1,0.36,0.34,1]};
_camstart = if (playerSide == blufor) then {markerPos QGVAR(camstart)} else {markerPos QGVAR(camstart_opfor)};
deleteMarkerLocal QGVAR(camstart);
deleteMarkerLocal QGVAR(camstart_opfor);
#endif

private "_camera";
_camera = "camera" camCreate [_camstart select 0, (_camstart select 1) + 1, 120];
_camera camSetTarget [getPosASL player select 0, getPosASL player select 1 , 1.5];
_camera camSetFov 0.7;
_camera cameraEffect ["INTERNAL", "Back"];
_camera camCommit 1;
waitUntil {camCommitted _camera};

#ifndef __TT__
_str = "One Team - " + GVAR(version_string);
_start_pos = 4;
_str2 = "";
if (GVAR(with_ai)) then {if (_str2 != "") then {_str2 = _str2 + " AI"} else {_str2 = _str2 + "AI"}};
if (GVAR(with_ranked)) then {if (_str2 != "") then {_str2 = _str2 + " RA"} else {_str2 = _str2 + "RA"}};
if (GVAR(WithRevive) == 0) then {if (_str2 != "") then {_str2 = _str2 + " REVIVE"} else {_str2 = _str2 + "REVIVE"}};
_sarray = toArray (_str2);
_start_pos2 = switch (count _sarray) do {
	case 2: {11};
	case 3: {11};
	case 4: {10};
	case 5: {10};
	case 6: {9};
	case 7: {9};
	case 8: {8};
	case 9: {8};
	case 10: {8};
	case 11: {7};
	case 12: {6};
	case 13: {5};
	case 14: {5};
	case 15: {4};
	case 16: {3};
	default {0};
};
#else
_str = "Two Teams";
_str2 = "";
_sarray = [];
_start_pos = 8;
#endif

2 cutRsc ["XDomLabel","PLAIN",2];
3 cutRsc ["XDomAward","PLAIN",2];
4 cutRsc ["XDomTwo", "PLAIN",2];
5 cutRsc ["XArmaLogo","PLAIN",2];
[_start_pos, _str, 5] execVM "IntroAnim\animateLettersX.sqf";__INC(_line); waitUntil {GVAR(animL_i) == _line};
if (count _sarray > 0) then {[_start_pos2, _str2, 6] execVM "IntroAnim\animateLettersX.sqf";__INC(_line); waitUntil {GVAR(animL_i) == _line}};
switch (GVAR(MissionType)) do {
	case 2: {
		[4, (localize "STR_DOM_MISSIONSTRING_263"), 4] execVM "IntroAnim\animateLettersX.sqf";__INC(_line); waitUntil {GVAR(animL_i) == _line};
	};
	case 1: {
		[4, (localize "STR_DOM_MISSIONSTRING_264"), 4] execVM "IntroAnim\animateLettersX.sqf";__INC(_line); waitUntil {GVAR(animL_i) == _line};
	};
};

_camera camSetTarget player;

_p_tpos = [getPosASL player select 0, getPosASL player select 1, 2];
_camera camSetPos _p_tpos;
_camera camCommit 18;

0 spawn {
	private ["_control", "_posdom", "_control2", "_pos", "_oldy"];
	disableSerialization;
	sleep 3;
	_control = __uiGetVar(XDomLabel) displayCtrl 50;
	_posdom = ctrlPosition _control;
	_control ctrlSetPosition [(_posdom select 0) - 0.08, _posdom select 1];
	_control ctrlCommit 0.3;
	waitUntil {ctrlCommitted _control};
	_control2 = __uiGetVar(XDomTwo) displayCtrl 50;
	_pos = ctrlPosition _control2;
	_control2 ctrlSetPosition [0.69, _pos select 1];
	_control2 ctrlCommit 0.5;
	waitUntil {ctrlCommitted _control2};
	0 cutRsc [QGVAR(Lightning1),"PLAIN"];
	11 cutRsc [QGVAR(Eyeflare),"PLAIN"];
	sleep 0.1;
	playSound "DThunder";
};
55 cutRsc ["dXlabel","PLAIN"];
sleep 6;
waitUntil {camCommitted _camera};
deleteVehicle _arrow_over_head;
player cameraEffect ["terminate","back"];
camDestroy _camera;
closeDialog 0;

enableRadio true;
"dynamicBlur" ppEffectEnable false;

private "_uidcheck_done";
_uidcheck_done = false;
if (GVAR(reserved_slot) != "" && {str(player) == GVAR(reserved_slot)}) then {
	_uidcheck_done = true;
	execVM "x_client\x_reservedslot.sqf";
};
// TYRGHEN ADDITION
// diag_log format["Reserved: %1",[(isnil "mp_rights_fnc_hasRoles"),toUpper str(player),GVAR(uid_reserved_slots)]];
if (isnil "mp_rights_fnc_hasRoles") then {
	if (!_uidcheck_done && {count GVAR(uid_reserved_slots) > 0} && {count GVAR(uids_for_reserved_slots) > 0}) then {
		for "_xi" from 0 to (count GVAR(uid_reserved_slots) - 1) do {
			GVAR(uid_reserved_slots) set [_xi, toUpper (GVAR(uid_reserved_slots) select _xi)];
		};
		if (toUpper str(player) in GVAR(uid_reserved_slots)) then {
			if !(getPlayerUID player in GVAR(uids_for_reserved_slots)) then {
				execVM "x_client\x_reservedslot2.sqf";
			};
			GVAR(uid_reserved_slots) = nil;
			GVAR(uids_for_reserved_slots) = nil;
		};
	};
} else {
	if (!_uidcheck_done && {count GVAR(uid_reserved_slots) > 0}) then {
		for "_xi" from 0 to (count GVAR(uid_reserved_slots) - 1) do {
			GVAR(uid_reserved_slots) set [_xi, toUpper (GVAR(uid_reserved_slots) select _xi)];
		};
		if (toUpper str(player) in GVAR(uid_reserved_slots)) then {
			if !(([player] call mp_rights_fnc_isMember)) then {
				execVM "x_client\x_reservedslot2.sqf";
			};
			GVAR(uid_reserved_slots) = nil;
			GVAR(uids_for_reserved_slots) = nil;
		};
	};
};

GVAR(still_in_intro) = false;

sleep 5;

[[[localize "STR_DOM_MISSIONSTRING_265","<t size='1.0' font='PuristaMedium'>%1</t><br/>",0],[name player,"<t size='1.0' font='PuristaBold'>%1</t><br/>",5],[localize "STR_DOM_MISSIONSTRING_266","<t size='0.9'>%1</t><br/>",27]],-safezoneX,0.85,"<t color='#FFFFFFFF' align='right'>%1</t>"] spawn BFUNC(typeText);

sleep 1;
if (!isNil QGVAR(server_name)) then {
	if (isNil QGVAR(player_stats)) then {
		systemChat format [localize "STR_DOM_MISSIONSTRING_1438", name player, GVAR(server_name)];
	} else {
		if (GVAR(player_stats) select 2 > 0) then {
			systemChat format [localize "STR_DOM_MISSIONSTRING_1439", name player, GVAR(server_name)];
		} else {
			systemChat format [localize "STR_DOM_MISSIONSTRING_1438", name player, GVAR(server_name)];
		};
	};
};
if (!isNil QGVAR(player_stats)) then {
	systemChat format [localize "STR_DOM_MISSIONSTRING_1440", GVAR(player_stats) select 2, (GVAR(player_stats) select 1) call FUNC(ConvertTime), GVAR(player_stats) select 0];
};
sleep 7;
123123 cutText [format [localize "STR_DOM_MISSIONSTRING_1434", actionKeysNames "TeamSwitch"], "PLAIN"];
sleep 9;
123123 cutText [format [localize "STR_DOM_MISSIONSTRING_2037", actionKeysNames "GetOver"], "PLAIN"];
xr_phd_invulnerable = false;

sleep 12;
123125 cutText ["You are not allowed to monetize videos made while playing Domination!!!\nYou are also not allowed to livestream while playing Domination!!!", "PLAIN"];

0 spawn {
	sleep 20;
	while {true} do {
		sleep (280 + random 280);
		467 cutRsc [QGVAR(restrict), "PLAIN"];
	};
};